home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / comm / mail / YAM23src.lha / Source / extrasrc / wbpath.c < prev   
C/C++ Source or Header  |  2000-12-15  |  1KB  |  70 lines

  1. #include <workbench/startup.h>
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4.  
  5. struct PathNode {
  6.    BPTR next;
  7.    BPTR dir;
  8. };
  9.  
  10. BPTR cloneWorkbenchPath(struct ExecBase *SysBase,
  11.             struct DosLibrary *DOSBase,
  12.             struct WBStartup *wbmsg)
  13. {
  14.    BPTR path = 0;
  15.  
  16.    Forbid();
  17.    if (wbmsg->sm_Message.mn_ReplyPort)
  18.    {
  19.       if (((LONG)wbmsg->sm_Message.mn_ReplyPort->mp_Flags & PF_ACTION) == PA_SIGNAL)
  20.       {
  21.      struct Process *wbproc = wbmsg->sm_Message.mn_ReplyPort->mp_SigTask;
  22.      if (wbproc->pr_Task.tc_Node.ln_Type == NT_PROCESS)
  23.      {
  24.         struct CommandLineInterface *cli = BADDR(wbproc->pr_CLI);
  25.         if (cli)
  26.         {
  27.            BPTR *p = &path;
  28.            BPTR dir = cli->cli_CommandDir;
  29.            while (dir)
  30.            {
  31.           BPTR dir2;
  32.           struct FileLock *lock = BADDR(dir);
  33.           struct PathNode *node;
  34.           dir = lock->fl_Link;
  35.           dir2 = DupLock(lock->fl_Key);
  36.           if (!dir2)
  37.              break;
  38.           node = AllocVec(8, MEMF_PUBLIC);
  39.           if (!node)
  40.           {
  41.              UnLock(dir2);
  42.              break;
  43.           }
  44.           node->next = 0;
  45.           node->dir = dir2;
  46.           *p = MKBADDR(node);
  47.           p = &node->next; 
  48.            }
  49.         }
  50.      }
  51.       }
  52.    }
  53.    Permit();
  54.  
  55.    return path;
  56. }
  57.  
  58. void freeWorkbenchPath(struct ExecBase *SysBase,
  59.                struct DosLibrary *DOSBase,
  60.                BPTR path)
  61. {
  62.    while (path)
  63.    {
  64.       struct PathNode *node = BADDR(path);
  65.       path = node->next;
  66.       UnLock(node->dir);
  67.       FreeVec(node);
  68.    }
  69. }
  70.